package com.marvels.financial.collection.controller;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.marvels.common.dto.MarvelsResultDTO;
import com.marvels.common.exception.MarvelsBusinessException;
import com.marvels.common.exception.MarvelsErrorCode;
import com.marvels.common.utils.MarvelsLogUtil;
import com.marvels.financial.collection.dto.IntelligentCollectDTO;
import com.marvels.financial.collection.service.IntelligentCollectApi;


/**
 * 智能催收配置
 * 
 * @author tangpw
 *
 */
@RequestMapping("financial/collection/intelligent/service")
@RestController
public class IntelligentCollectController {

	@Autowired
	private IntelligentCollectApi collectApi;
	
	@InitBinder
	public void initBinder(WebDataBinder binder) {
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		dateFormat.setLenient(false);
		binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
	}

	/**
	 * 新增智能催收配置
	 * @param collectDTO
	 * @return
	 */
	@RequestMapping("addCollectionConfig")
	@ResponseBody
	public MarvelsResultDTO addCollectionConfig(@RequestBody IntelligentCollectDTO collectDTO) {
		try {
			collectApi.addCollectionConfig(collectDTO);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(), null);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>新增智能催收配置FAIL:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), e.getMessage(), null);
		}catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>新增智能催收配置异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), "新增智能催收配置异常", null);
		}

	}

}
